<style>
	.layui-laypage{
		margin:10px auto;
	}
</style>
<div class="row" style="height:100%;">
	<div class="col-lg-12" style="border-right:1px solid #e6e6e6;padding-right:0px;">
		<h1 class="site-h1" style="background-color:#FFFFFF;">
			分机列表<#if extentionPageList??>（${extentionPageList.totalElements!'0'}）</#if>

			<span style="float:right;">
				<div class="layui-inline">
					<div class="layui-input-inline">
						<input type="text" name="ext" id="ext" oninput="inlineearch()" value="" style="height: 30px;line-height: 30px;margin-top: 4px;border: 1px solid #32c24d;" placeholder="请输入查询条件" autocomplete="off" class="layui-input">
						<i class="layui-icon" onclick="inlineearch()" style="position: absolute;cursor: pointer;right: 3px;top: 4px;font-size: 20px;color:#32c24d;"></i>
					</div>
				</div>
				<#if !ismy?? || (ismy?? && !ismy)>
				<button class="layui-btn layui-btn-sm green" href="/admin/callcenter/extention/add.html?hostid=${pbxHost.id!''}" data-toggle="ajax" data-width="700" data-height="650" data-title="添加新分机">
					添加分机（支持批量添加）
				</button>

				<#if callcentershowall?? && callcentershowall == true>
					<button class="layui-btn layui-btn-sm green" href="/admin/callcenter/extention/assign.html?hostid=${pbxHost.id!''}" data-toggle="ajax" data-width="700" data-height="650" data-title="分配分机">
					分配分机（多租户）
					</button>
				</#if>
				<#else>
					<button class="layui-btn layui-btn-sm green" href="/admin/mycallcenter/extention/add.html?hostid=${pbxHost.id!''}" data-toggle="ajax" data-width="700" data-height="650" data-title="添加新IVR分机">
						添加IVR分机
					</button>
				</#if>
				<button class="layui-btn layui-btn-sm" id="dischecked" href="javascript:void(0)" data-toggle="ajax" data-width="950" data-height="450" data-title="批量修改分机">
					批量修改分机
				</button>
				<a class="layui-btn layui-btn-sm layui-btn-danger" href="javascript:void(0)" id="batdel" data-toggle="tip" data-callback="loadURL" data-target="#callCenterContent"  data-title="请确认是否删除选择的分机？">
					批量删除
				</a>
			</span>
		</h1>
		<div class="row">
			<div class="col-lg-12">
				<#if callcentershowall?? && callcentershowall == true && (!ismy?? || (ismy?? && !ismy))>
				<div class="row layui-form">
						<div class="ukefu-bt-text-content">
							<table class="layui-table" lay-skin="nob">
								<tbody>
								<tr class="tdHasContorllor design-dropable-td">

									<td width="1%" nowrap="nowrap">租户ID：</td>
									<td width="20%">
										<select name="orgi" id="extentionOrgi">
											<option value="">请选择租户ID</option>
											<#if tenantList??>
											<#list tenantList as tenant>
											<option value="${tenant.tenantcode!''}" <#if orgi1?? && orgi1 == tenant.tenantcode>selected="selected"</#if>>${tenant.tenantcode!''}</option>
											</#list>
										</#if>
										</select>
										</td>

									<td width="1%" nowrap="nowrap">分配状态：</td>
									<td width="20%">
										<select name="isassigned" id="isassigned">
											<option value="">请选择分配状态</option>
											<option value="true" <#if isassigned?? && isassigned?string == 'true'>selected="selected"</#if>>已分配</option>
										<option value="false" <#if isassigned?? && isassigned?string == 'false'>selected="selected"</#if>>未分配</option>
									</select>
									</td>

									<td width="1%" nowrap="nowrap">
										<button class="layui-btn layui-btn-sm" id="extentionSearch">
											<i class="layui-icon">&#xe615;</i>
											查询
										</button>
									</td>

								</tr>
								</tbody>
							</table>

						</div>
				</div>
				</#if>
				<div class="row" style="padding:5px;">
					<div class="col-lg-12">
						<table class="layui-table" lay-skin="line">
						  <colgroup>
						  		<col width="1%">
								<col width="18%">
								<col width="10%">
								<col width="10%">
								<col width="20%">
								<col width="10%">
								<col width="10%">
								<col width="10%">
								<#if callcentershowall?? && callcentershowall == true && (!ismy?? || (ismy?? && !ismy))><col width="5%"></#if>
								<#if callcentershowall?? && callcentershowall == true && (!ismy?? || (ismy?? && !ismy))><col width="5%"></#if>
								<col width="1%">
								<col>
						  </colgroup>
						  <thead>
							<tr>
							  <th>
								  <input type="checkbox" id="all" onclick="$('.ids').prop('checked' , $(this).prop('checked'));"/>
							  </th>
							  <th>分机号</th>
							  <th>外呼</th>
							  <th>录音</th>
							  <th>网关/号码</th>
							  <th>类型</th>
							  <th>WebRTC</th>
							  <th>自动接听</th>
							  <#if callcentershowall?? && callcentershowall == true && (!ismy?? || (ismy?? && !ismy))><th>租户ID</th></#if>
							<#if callcentershowall?? && callcentershowall == true && (!ismy?? || (ismy?? && !ismy))><th>是否分配</th></#if>
							  <th style="white-space:nowrap;" nowrap="nowrap">操作</th>
							</tr> 
						  </thead>
						  <tbody>
							<#if extentionList??>
							<#list extentionList as extention>
							<tr class="row-data">
							  <td style="width:1%;">
								 <input type="checkbox" class="ids" name="ids" value="${extention.id!''}"/>
							  </td>
							  <td class="extention">
									${extention.extention!''}
									<#if extention.description?? && extention.description != "">（${extention.description!''}）</#if>
									<#if extention.username?? && extention.username != "">（${extention.username!''}）</#if>
							  </td>
							  <td>
									<#if extention.callout>
								  		<i class="layui-icon" style="color:#19a55d;">&#xe605;</i>
								  	</#if>
							  </td>
							  <td>
									<#if extention.record>
								  		<i class="layui-icon" style="color:#19a55d;">&#xe605;</i>
								  	</#if>
							  </td>
							  <td class="gateway">
									<#if extention.siptrunk?? && extention.siptrunk != "">
								  		<#if sipTrunkListList??>
								  		<#list sipTrunkListList as sipTrunk>
								  		<#if sipTrunk.id == extention.siptrunk>${sipTrunk.name!''}</#if>
								  		</#list>
								  		</#if>
								  		<#if extention.outnum?? && extention.outnum!="">/${extention.outnum!''}</#if>
								  	</#if>
							  </td>
							  <td>
									<#if extention.extype?? && extention.extype == "line">直线</#if>
									<#if extention.extype?? && extention.extype == "ivr">
										
										<#if extention.enableai?? && extention.enableai == "1">
										智能IVR<i class="kfont" style="position: relative;" title="启用智能 机器人">&#xe63a;</i>
										<#else>
										IVR
										</#if>
									</#if>
									<#if extention.extype?? && extention.extype == "business">业务</#if>
									<#if extention.extype?? && extention.extype == "skill">技能组</#if>
									<#if extention.extype?? && extention.extype == "conference">会议</#if>
									<#if extention.extype?? && extention.extype == "quene">队列</#if>
							  </td>
							  <td>
									<#if extention.enablewebrtc?? && extention.enablewebrtc == true>
									<i class="layui-icon" style="color:#19a55d;">&#xe605;</i>
									</#if>
							  </td>
							   <td>
									<#if extention.autoanswer?? && extention.autoanswer == "all">
									<i class="layui-icon" style="color:#19a55d;">&#xe605;</i>
									<#elseif extention.autoanswer?? && extention.autoanswer == "queue">
									<i class="layui-icon" style="color:#19a55d;">&#xe605;</i>
									</#if>
							  </td>
							  <#if callcentershowall?? && callcentershowall == true && (!ismy?? || (ismy?? && !ismy))>
							  <td>
							  	${extention.orgi!''}
							  </td>
							  </#if>
								<#if callcentershowall?? && callcentershowall == true && (!ismy?? || (ismy?? && !ismy))>
									<td><#if extention.assigned?? && extention.assigned == true>是<#else>否</#if></td>
								</#if>
							  <td style="white-space:nowrap;" nowrap="nowrap">
							  		<a href="/admin/callcenter/extention/edit.html?id=${extention.id!''}&hostid=${pbxHost.id!''}&p=${p!''}<#if ismy?? && ismy>&ismy=true</#if>" data-toggle="ajax" data-width="700" data-height="450" data-title="编辑分机信息">
							  			<i class="layui-icon">&#xe642;</i>
							  			编辑
							  		</a>
									<#if models?? && models["calloutai"]?? && models["calloutai"] == true>
										<#if extention.extype?? && extention.extype == "ivr">
										<a href="/admin/callcenter/extention/ivr.html?id=${extention.id!''}&hostid=${pbxHost.id!''}&p=${p!''}<#if ismy?? && ismy>&ismy=true</#if>" style="margin-left:10px;" data-toggle="ajax" data-width="700" data-height="450" data-title="编辑IVR配置信息">
											<i class="kfont">&#xe66f;</i>
											IVR配置
										</a>
										</#if>
									</#if>
							  		<#if !ismy?? || (ismy?? && !ismy)>
							  		<a href="/admin/callcenter/extention/delete.html?id=${extention.id!''}&hostid=${pbxHost.id!''}" style="margin-left:10px;" data-toggle="tip" data-callback="loadURL" data-target="#callCenterContent" data-title="请确认是否删除分机号？">
							  			<i class="layui-icon" style="color:red;">&#x1006;</i>
							  			删除
							  		</a>
							  		</#if>

									<#if callcentershowall?? && callcentershowall == true && (!ismy?? || (ismy?? && !ismy)) && extention.assigned?? && extention.assigned == true>
									<a href="/admin/callcenter/extention/cancelassigned.html?id=${extention.id!''}&hostid=${pbxHost.id!''}&p=${p!''}" style="margin-left:10px;" data-toggle="tip" data-callback="loadURL" data-target="#callCenterContent" data-title="请确认是否取消分配分机号？">
										<i class="layui-icon" style="color:red;">&#x1006;</i>
										取消分配
									</a>
									</#if>
							  </td>
							</tr>
							</#list>
							</#if>
						  </tbody>
						</table>
						<#if callcentershowall?? && callcentershowall == true><div class="row" id="page" style="text-align:center;"></div></#if>

					</div> 	   
				</div>
			</div>	
		</div>
	</div>	
</div>
<script>
	var layer ;
	var table;
	layui.use('form', function() {
		var form = layui.form;
		form.render();

	});

	var laypage;

	layui.use(['table','layer','laypage'], function() {
		table = layui.table;
		layer = layui.layer;
		laypage = layui.laypage;

		<#if extentionPageList??>
		laypage.render({
			elem: 'page'
			,pages: <#if extentionPageList??>${extentionPageList.totalPages}<#else>0</#if> //总页数
				,curr:<#if extentionPageList??>${extentionPageList.number+1}<#else>0</#if>
				,groups: 5 //连续显示分页数
				,jump:function(data , first){
			if(!first){
				loadURL("/admin/callcenter/extention.html?hostid=${pbxHost.id!''}&p="+data.curr<#if orgi1?? > +  "&orgi=${orgi1!''}"</#if><#if isassigned??> + "&isassigned=${isassigned!''}"</#if> ,"#callCenterContent");
				}
			}
		});
		</#if>


		$("#extentionSearch").click(function(){
			var orgi = $("#extentionOrgi").val();
			orgi = !!orgi?orgi:"";
			var isassigned = $("#isassigned").val();
			isassigned = !!isassigned?isassigned:"";

			loadURL("/admin/callcenter/extention.html?hostid=${pbxHost.id!''}&p=1&orgi=" + orgi + "&isassigned=" + isassigned ,"#callCenterContent");
		})


	});
	
	$('#dischecked').click(function(){
		var ids = "";
		var num = 0 ;
		
		$('.ids').each(function(){
			if($(this).prop("checked") && $(this).parents(".row-data").is(":hidden") == false){
				if(ids!=""){
					ids += "&" ;
				}
				ids += "ids=" + $(this).val();
				num++;
			}
		});
		if(num>0){
			$('#dischecked').attr('href' , '/admin/callcenter/extention/batedit.html?hostid=${pbxHost.id!''}&'+ids)	;
		}else{
			top.layer.alert("请先选择需要批量修改的分机");
			$('#dischecked').attr("href" , "javascript:void(0)");
		}
	});
	function inlineearch(){
		$(".row-data").each(function(){
			if($("#ext").val().trim() != ""){
	            $(this).hide(); //先隐藏所有tr
	            //判断第二列“td：eq(1)”是否包含搜索内容
	            if($(this).find(".extention,.gateway").text().indexOf($("#ext").val())>=0){
	                $(this).show();  //显示搜索到的部分   
	            }
	        }else{
	            $(this).show();  //显示所有内容
	        }
		});
	}
	$(document).ready(function(){
		$('.row-data').on("click",function(){
			var ids = $(this).find(".ids") ;
			if(ids.length > 0){
				$(ids[0]).prop("checked" , !($(ids[0]).prop("checked")));
			}
		});
		
		$('#batdel').click(function(){
			var ids = "";
			$('.ids').each(function(){
				if($(this).prop("checked") && $(this).parents(".row-data").is(":hidden") == false){
					if(ids!=""){
						ids += "&" ;
					}
					ids += "ids=" + $(this).val();
				}
			});
			if(ids==''){
				top.layer.alert("请选择需要删除的分机！", {icon: 7});
			}else{
				$('#batdel').attr('href' , "/admin/callcenter/extention/batdelete.html?hostid=${pbxHost.id!''}&"+ids)	;
			}
			
		});
	});
</script>

